
import UtilsRockerDirection from '../Utils.rockerDirection/UtilsRockerDirection';

const _eightDirections = Symbol('_eightDirections');
const _fourDirections = Symbol('_fourDirections');
const _error = Symbol('_error');
export class UtilsBindRockerSwitchFrameAnima {
    constructor(_options, _that) {
        if (!_options) return this[_error]('no options?');
        this.options = _options;
        if (_options.type == 'eightDirections') this[_eightDirections](_that);
        if (_options.type == 'fourDirections') this[_fourDirections](_that);
    }

    [_eightDirections](_that) {
        UtilsRockerDirection.init({
            RockerDirection: {
                type: 'recordLastUpEight',
                lastUpKey: this.options.RockerDirection.lastUp,
                deltaY: this.options.RockerDirection.deltaY,
                deltaX: this.options.RockerDirection.deltaX
            }
        }, _that);
        _that.direction = UtilsRockerDirection.init(this.options, '', _that[this.options.RockerDirection.lastUp]);
        switch (_that.direction) {
            case 2:
                DemonMoveTopInteraction.init(_that, this.options.spriteKey);
                delete DemonMoveTopRightInteraction.instance;
                delete DemonMoveRightInteraction.instance;
                delete DemonMoveBottomRightInteraction.instance;
                delete DemonMoveBottomInteraction.instance;
                delete DemonMoveBottomLeftInteraction.instance;
                delete DemonMoveLeftInteraction.instance;
                delete DemonMoveTopLefttInteraction.instance;
                break;
            case 3:
                DemonMoveTopRightInteraction.init(_that, this.options.spriteKey);
                delete DemonMoveTopInteraction.instance;
                delete DemonMoveRightInteraction.instance;
                delete DemonMoveBottomRightInteraction.instance;
                delete DemonMoveBottomInteraction.instance;
                delete DemonMoveBottomLeftInteraction.instance;
                delete DemonMoveLeftInteraction.instance;
                delete DemonMoveTopLefttInteraction.instance;
                break;
            case 4:
                DemonMoveRightInteraction.init(_that, this.options.spriteKey);
                delete DemonMoveTopInteraction.instance;
                delete DemonMoveTopRightInteraction.instance;
                delete DemonMoveBottomRightInteraction.instance;
                delete DemonMoveBottomInteraction.instance;
                delete DemonMoveBottomLeftInteraction.instance;
                delete DemonMoveLeftInteraction.instance;
                delete DemonMoveTopLefttInteraction.instance;
                break;
            case 5:
                DemonMoveBottomRightInteraction.init(_that, this.options.spriteKey);
                delete DemonMoveTopInteraction.instance;
                delete DemonMoveTopRightInteraction.instance;
                delete DemonMoveRightInteraction.instance;
                delete DemonMoveBottomInteraction.instance;
                delete DemonMoveBottomLeftInteraction.instance;
                delete DemonMoveLeftInteraction.instance;
                delete DemonMoveTopLefttInteraction.instance;
                break;
            case 6:
                DemonMoveBottomInteraction.init(_that, this.options.spriteKey);
                delete DemonMoveTopInteraction.instance;
                delete DemonMoveTopRightInteraction.instance;
                delete DemonMoveRightInteraction.instance;
                delete DemonMoveBottomRightInteraction.instance;
                delete DemonMoveBottomLeftInteraction.instance;
                delete DemonMoveLeftInteraction.instance;
                delete DemonMoveTopLefttInteraction.instance;
                break;
            case 7:
                DemonMoveBottomLeftInteraction.init(_that, this.options.spriteKey);
                delete DemonMoveTopInteraction.instance;
                delete DemonMoveTopRightInteraction.instance;
                delete DemonMoveRightInteraction.instance;
                delete DemonMoveBottomRightInteraction.instance;
                delete DemonMoveBottomInteraction.instance;
                delete DemonMoveLeftInteraction.instance;
                delete DemonMoveTopLefttInteraction.instance;
                break;
            case 0:
                DemonMoveLeftInteraction.init(_that, this.options.spriteKey);
                delete DemonMoveTopInteraction.instance;
                delete DemonMoveTopRightInteraction.instance;
                delete DemonMoveRightInteraction.instance;
                delete DemonMoveBottomRightInteraction.instance;
                delete DemonMoveBottomInteraction.instance;
                delete DemonMoveBottomLeftInteraction.instance;
                delete DemonMoveTopLefttInteraction.instance;
                break;
            case 1:
                DemonMoveTopLefttInteraction.init(_that, this.options.spriteKey);
                delete DemonMoveTopInteraction.instance;
                delete DemonMoveTopRightInteraction.instance;
                delete DemonMoveRightInteraction.instance;
                delete DemonMoveBottomRightInteraction.instance;
                delete DemonMoveBottomInteraction.instance;
                delete DemonMoveBottomLeftInteraction.instance;
                delete DemonMoveLeftInteraction.instance;
                break;
        }
    }

    [_fourDirections]() {

    }

    [_error](err) {
        throw err;
    }

}

const _init = Symbol('_init');
export class SwitchFrameAttackAnima {
    constructor(_dkey, _key, _that) {
        if (!_dkey) return this[_error]('no key?');
        this.dkey = _dkey;
        this.key = _key;
        this[_init](_that);
    }

    [_init](_that) {
        console.log(_that[this.dkey])
        switch (_that[this.dkey]) {
            case 2:
                _that[this.key].play('demonAttackTopAnima');
                break;
            case 3:
                _that[this.key].play('demonAttackTopRightAnima');
                break;
            case 4:
                _that[this.key].play('demonAttackRightAnima');
                break;
            case 5:
                _that[this.key].play('demonAttackBottomRightAnima');
                break;
            case 6:
                _that[this.key].play('demonAttackBottomAnima');
                break;
            case 7:
                _that[this.key].play('demonAttackBottomLeftAnima');
                break;
            case 0:
                _that[this.key].play('demonAttackLeftAnima');
                break;
            case 1:
                _that[this.key].play('demonAttackTopLeftAnima');
                break;
        }

        _that[this.key].on('animationcomplete', e => {
            // console.log('动画加载完毕...', e);
            switch (e.key) {
                case 'demonAttackTopAnima':
                    delete DemonMoveTopInteraction.instance;
                    new DemonMoveTopInteraction.init(_that, this.key);
                    break;
                case 'demonAttackTopRightAnima':
                    delete DemonMoveTopRightInteraction.instance;
                    new DemonMoveTopRightInteraction.init(_that, this.key);
                    break;
                case 'demonAttackRightAnima':
                    delete DemonMoveRightInteraction.instance;
                    new DemonMoveRightInteraction.init(_that, this.key);
                    break;
                case 'demonAttackBottomRightAnima':
                    delete DemonMoveBottomRightInteraction.instance;
                    new DemonMoveBottomRightInteraction.init(_that, this.key);
                    break;
                case 'demonAttackBottomAnima':
                    delete DemonMoveBottomInteraction.instance;
                    new DemonMoveBottomInteraction.init(_that, this.key);
                    break;
                case 'demonAttackBottomLeftAnima':
                    delete DemonMoveBottomLeftInteraction.instance;
                    new DemonMoveBottomLeftInteraction.init(_that, this.key);
                    break;
                case 'demonAttackLeftAnima':
                    delete DemonMoveLeftInteraction.instance;
                    new DemonMoveLeftInteraction.init(_that, this.key);
                    break;
                case 'demonAttackTopLeftAnima':
                    delete DemonMoveTopLefttInteraction.instance;
                    new DemonMoveTopLefttInteraction.init(_that, this.key);
                    break;
            }
        })
    }

    [_error](err) {
        throw err;
    }
}

/**
 * @class DemonMoveTopInteraction 帧动画单例壳
 */
class DemonMoveTopInteraction {
    static interaction(_that, _spriteKey) {
        _that[_spriteKey].anims.play(`demonMoveTopAnima`, true);
    }

    static init(_that, _spriteKey) {
        if (!DemonMoveTopInteraction.instance) {
            DemonMoveTopInteraction.instance = new DemonMoveTopInteraction();
            DemonMoveTopInteraction.interaction(_that, _spriteKey);
        }
        return DemonMoveTopInteraction.instance;
    }
}

/**
 * @class DemonMoveTopRightInteraction 帧动画单例壳
 */
class DemonMoveTopRightInteraction {
    static interaction(_that, _spriteKey) {
        _that[_spriteKey].anims.play(`demonMoveTopRightAnima`, true);
    }

    static init(_that, _spriteKey) {
        if (!DemonMoveTopRightInteraction.instance) {
            DemonMoveTopRightInteraction.instance = new DemonMoveTopRightInteraction();
            DemonMoveTopRightInteraction.interaction(_that, _spriteKey);
        }
        return DemonMoveTopRightInteraction.instance;
    }
}

/**
 * @class DemonMoveRightInteraction 帧动画单例壳
 */
class DemonMoveRightInteraction {
    static interaction(_that, _spriteKey) {
        _that[_spriteKey].anims.play(`demonMoveRightAnima`, true);
    }

    static init(_that, _spriteKey) {
        if (!DemonMoveRightInteraction.instance) {
            DemonMoveRightInteraction.instance = new DemonMoveRightInteraction();
            DemonMoveRightInteraction.interaction(_that, _spriteKey);
        }
        return DemonMoveRightInteraction.instance;
    }
}

/**
 * @class DemonMoveBottomRightInteraction 帧动画单例壳
 */
class DemonMoveBottomRightInteraction {
    static interaction(_that, _spriteKey) {
        _that[_spriteKey].anims.play(`demonMoveBottomRightAnima`, true);
    }

    static init(_that, _spriteKey) {
        if (!DemonMoveBottomRightInteraction.instance) {
            DemonMoveBottomRightInteraction.instance = new DemonMoveBottomRightInteraction();
            DemonMoveBottomRightInteraction.interaction(_that, _spriteKey);
        }
        return DemonMoveBottomRightInteraction.instance;
    }
}

/**
 * @class DemonMoveBottomInteraction 帧动画单例壳
 */
class DemonMoveBottomInteraction {
    static interaction(_that, _spriteKey) {
        _that[_spriteKey].anims.play(`demonMoveBottomAnima`, true);
    }

    static init(_that, _spriteKey) {
        if (!DemonMoveBottomInteraction.instance) {
            DemonMoveBottomInteraction.instance = new DemonMoveBottomInteraction();
            DemonMoveBottomInteraction.interaction(_that, _spriteKey);
        }
        return DemonMoveBottomInteraction.instance;
    }
}

/**
 * @class DemonMoveBottomLeftInteraction 帧动画单例壳
 */
class DemonMoveBottomLeftInteraction {
    static interaction(_that, _spriteKey) {
        _that[_spriteKey].anims.play(`demonMoveBottomLeftAnima`, true);
    }

    static init(_that, _spriteKey) {
        if (!DemonMoveBottomLeftInteraction.instance) {
            DemonMoveBottomLeftInteraction.instance = new DemonMoveBottomLeftInteraction();
            DemonMoveBottomLeftInteraction.interaction(_that, _spriteKey);
        }
        return DemonMoveBottomLeftInteraction.instance;
    }
}

/**
 * @class DemonMoveLeftInteraction 帧动画单例壳
 */
class DemonMoveLeftInteraction {
    static interaction(_that, _spriteKey) {
        _that[_spriteKey].anims.play(`demonMoveLeftAnima`, true);
    }

    static init(_that, _spriteKey) {
        if (!DemonMoveLeftInteraction.instance) {
            DemonMoveLeftInteraction.instance = new DemonMoveLeftInteraction();
            DemonMoveLeftInteraction.interaction(_that, _spriteKey);
        }
        return DemonMoveLeftInteraction.instance;
    }
}

/**
 * @class DemonMoveTopLefttInteraction 帧动画单例壳
 */
class DemonMoveTopLefttInteraction {
    static interaction(_that, _spriteKey) {
        _that[_spriteKey].anims.play(`demonMoveTopLefttAnima`, true);
    }

    static init(_that, _spriteKey) {
        if (!DemonMoveTopLefttInteraction.instance) {
            DemonMoveTopLefttInteraction.instance = new DemonMoveTopLefttInteraction();
            DemonMoveTopLefttInteraction.interaction(_that, _spriteKey);
        }
        return DemonMoveTopLefttInteraction.instance;
    }
}